<template>
	<view >
		<form  @submit="formSubmit" >
				
			<view class="muokuai">
				<view class="mokuai_title">花费(￥)</view>
				<view class="text_f">
					<input name='qian'  type="digit" auto-focus placeholder="500" />
				</view>
			</view>		
				
				
			<view class="muokuai">
				<view class="mokuai_title">分类</view>
				<view style="padding: 10px 0">
				  <picker @change="bindChange" name="fenglei"  :value="index" :range="array">
					<view style="padding-left: 15px;">
					  请选择：{{array[index]}}
					</view>
				  </picker>
				</view>
			</view>
				
			
			<view class="muokuai">
				<view class="mokuai_title">备注</view>
				<view >
				  <view class="text_f">
					<input name="beizhu" placeholder="火锅" />
				  </view>
				</view>
			</view>
				
				
			<view class="muokuai">
				<view >
					<view class="mokuai_title">
						选择日期
					</view>
					<view class="text_f">
						<picker name='rqi' mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
							<view >{{date}}</view>
						</picker>
					</view>
				</view>
			</view>
					
			<view style="width: 100%;text-align: center;margin-top: 30%;">
				<button style="width: 66%;background-color: #e782D7;" type="primary"  form-type="submit">记一笔</button>
			</view>

		</form>
	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
			    format: true
			})
			return {
				title: 'Hello',
				money:500,
				array: ['餐饮', '交通', '通讯', '购物'],
				index:0,
				date: currentDate,
			}
		},
		onLoad() {

		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		methods: {
			bindDateChange: function(e) {
				this.date = e.detail.value
				// console.log(this.date)
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
	
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			formSubmit (e) {
				console.log('form发生了submit事件，携带数据为：' + JSON.stringify(e.detail.value))
				var formdata = e.detail.value	
				const userInfo = uni.getStorageSync('userInfo');
				formdata.appid = userInfo.appid	
				formdata.fenglei = this.array[formdata.fenglei]
				console.log(formdata)
				const res = this.$myRequest({
					url:'/insertUser',
					data:formdata,
					method: 'post'
				})
				uni.showModal({
					content: '成功记下一笔',
					showCancel: false
				});

			},
				
			// formReset(e) {
			// 	console.log('清空数据')
			// }
			bindChange(e){
				this.index = e.detail.value
			}

		}
	}
</script>

<style>
	
.muokuai{
	width: 100%;
	height: 15%;
	/* background-color: #007AFF; */
	margin-top: 10px;
	padding-left: 15px;
}
	
.mokuai_title{
	color: #999999;
	font-size: 16px;
	padding-left: 15px;
	padding-bottom: 5px;
	border-bottom: 1px solid #C0C0C0;
}
.text_f{
	padding-left: 15px; 
	padding-top: 4px; 
	border-bottom: 1px solid #C0C0C0; 
	padding-bottom: 4px;
}
	
button{
	width: 100%;
}
</style>
